package com.hongyu.smart.village.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.hongyu.smart.village.R;
import com.hongyu.smart.village.event.Event;
import com.hongyu.smart.village.model.Family;
import com.hongyu.smart.village.model.entity.BaseResponse;
import com.hongyu.smart.village.network.BaseObserver;
import com.hongyu.smart.village.network.RetrofitHelper;
import com.hongyu.smart.village.network.RxUtil;
import com.hongyu.smart.village.network.api.AppInfoApi;
import com.hongyu.smart.village.ui.base.BaseToolbarActivity;
import com.hongyu.smart.village.util.SPUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class MyFamilyActivity extends BaseToolbarActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    int id=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public String getToolBarTitle() {
        return "我的家庭";
    }

    @Override
    protected void initActivityData() {
        if (id==0){


            return;
        }
        httpGetFamilyInfo();
    }

    @Override
    protected void initContentView() {
        if (resp!=null) {
            tvName.setText(resp.getNickname());
            tvPhone.setText(resp.getMobile());
            id=resp.getId();
        }




    }

    private void httpGetFamilyInfo() {
        RetrofitHelper.create(AppInfoApi.class)
                .familyFind(id)
                .compose(RxUtil.observervableToMain())
                .as(RxUtil.bindLifecycle( this))
                .subscribe(new BaseObserver<Family>(getLoadingDialog()){
                    @Override
                    public void onSuccess(BaseResponse<Family> response) {
                        if (response.getData()!=null) {
                            SPUtil.setFamilyNumber(response.getData().getNumber());
                            String number= SPUtil.getFamilyNumber();
                            Log.e("FamilyNumber",number);


                        }
                    }
                });
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_my_family;
    }

    @Override
    protected void onEventProcess(Event event) {

    }
    @OnClick({R.id.layout_memeber,R.id.layout_family})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.layout_memeber:
                sendIntent(MemberActivity.class);

                break;
            case R.id.layout_family:
                sendIntent(DomicileInforActivity.class);
                break;
        }
    }

}